package com.leyou.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.entity.SpecParam;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.mapper.SpecParamMapper;
import com.leyou.service.SpecParamService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper,SpecParam> implements SpecParamService {
    /**
     * 添加和修改共用一个
     * @param specParamDTO
     */
    @Override
    public void addSpecParam(SpecParamDTO specParamDTO) {

        SpecParam specParam = specParamDTO.toEntity(SpecParam.class);

        saveOrUpdate(specParam);


    }

    /**
     * 根据分类id和组id查询规格参数模板的集合
     * @param cid
     * @param groupId
     * @return
     */
    @Override
    public List<SpecParamDTO> getSpecParamDTOSByParams(Long cid, Long groupId,Boolean searching) {
        List<SpecParam> specParams = query().eq(null != cid, "category_id", cid)
                .eq(null != groupId, "group_id", groupId)
                .eq(null!=searching,"searching",searching).list();
        return SpecParamDTO.convertEntityList(specParams);
    }
}
